package org.example.java8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FilterApple {
    //查绿苹果
    public static List<Apple> findGreenApple(List<Apple> apples) {

        List<Apple> list = new ArrayList<>();
        for (Apple apple : apples) {
            if ("green".equals(apple.getColor())) {
                list.add(apple);
            }
        }
        return list;
    }

    //查各种颜色苹果
    public static List<Apple> findApple(List<Apple> apples,String color) {

        List<Apple> list = new ArrayList<>();
        for (Apple apple : apples) {
            if (color.equals(apple.getColor())) {
                list.add(apple);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        List<Apple> list = Arrays.asList(new Apple("green", 150), new Apple("yellow", 130), new Apple("green", 200));
        //List<Apple> greenApples = findGreenApple(list);
        //assert greenApples.size() == 2;
        //System.out.println(greenApples);

        List<Apple> greenApples = findApple(list,"green");
        System.out.println(greenApples);
        List<Apple> yellowApples = findApple(list,"yellow");
        System.out.println(yellowApples);

    }
}
